﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WindowsWeChat.Common;
using WindowsWeChat.Entity;

namespace WindowsWeChat.Control
{
    /// <summary>
    /// FaceItems.xaml 的交互逻辑
    /// </summary>
    public partial class FaceItems : UserControl
    {
        public delegate void CallBackHandler(FaceImageEntity fie);
        public CallBackHandler CallBack;
        List<FaceImageEntity> list = new List<FaceImageEntity>();

        public FaceItems()
        {
            InitializeComponent();
            string path = "pack://application:,,,/WindowsWeChat;component/Resource/Face/{0}.gif";
            for (int index = 1; index < 100; index++)
            {
                FaceImageEntity fie = new FaceImageEntity() { FilePath = string.Format(path, index) };
                list.Add(fie);
            }
            Itemsp.ItemsSource = list;
        }
        private static readonly DependencyProperty ClickCommandProperty = DependencyProperty.Register("ClickCommand", typeof(ICommand), typeof(FaceItems));
        /// <summary>
        /// 单击事件
        /// </summary>
        public ICommand ClickCommand
        {
            get
            {
                return (ICommand)GetValue(ClickCommandProperty);
            }
            set
            {
                SetValue(ClickCommandProperty, value);
            }
        }
        private void GifImage_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

            for (int index = 0; index < list.Count; index++)
            {
                if (list[index].FilePath == (sender as GifImage).Source)
                {
                    ClickCommand.Execute(list[index]);
                    break;
                }
            }
        }
    }
}
